package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.MoveDataVo;
import com.yjhh.chdataservice.beans.ObjMoveInStatisticsVo;
import com.yjhh.chdataservice.beans.ObjMoveInfoVo;
import com.yjhh.chdataservice.beans.ObjRZLResultVo;
import com.yjhh.chdataservice.beans.ObjRelocaSimpleInfoVo;
import com.yjhh.chdataservice.beans.ObjZPYYVo;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.FZJCObjService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by hlantian on 2017/9/26.
 */
@Api(tags = "对象模块相关接口")
@RestController
@RequestMapping(value = "/service/fzjc/obj")
@Log4j2
public class FZJCObjController {

    @Autowired
    private FZJCObjService fzjcService;


    @ApiOperation(value = "获取下级行政区划贫困户的统计信息", notes = "按照省、市、县的行政区划获取下级行政区划贫困户的统计信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610700000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjStaticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<MoveDataVo>> getObjStaticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<MoveDataVo>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcService.getObjStaticsByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjStaticsByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "获取乡镇级行政区划下贫困的信息", notes = "根据乡镇级的行政区划获取该行政区划下贫困的信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610721110000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPoorObjstaticsInfoByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<ObjRelocaSimpleInfoVo>> getPoorObjstaticsInfoByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<ObjRelocaSimpleInfoVo>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcService.getPoorObjstaticsInfoByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPoorObjstaticsInfoByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }


    @ApiOperation(value = "搬迁户入住率服务统计", notes = "搬迁户入住率服务")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjMoveInPercentByAreaCode", method = RequestMethod.GET)
    public CommonResultData<ObjRZLResultVo> getObjMoveInPercentByAreaCode(@RequestParam String areaCode) {
        CommonResultData<ObjRZLResultVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjMoveInPercentByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjMoveInPercentByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "搬迁户入住率服务统计(上报数据)", notes = "搬迁户入住率服务(上报数据)")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "611000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjMoveInPercentByAreaCodeReport", method = RequestMethod.GET)
    public CommonResultData<ObjRZLResultVo> getObjMoveInPercentByAreaCodeReport(@RequestParam String areaCode) {
        CommonResultData<ObjRZLResultVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjMoveInPercentByAreaCodeReport(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjMoveInPercentByAreaCodeReport", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "根据贫困户的ID返回贫困户的所有属性信息", notes = "根据贫困户的ID返回贫困户的所有属性信息")
    @ApiImplicitParam(name = "id", value = "贫困户ID", required = true, paramType = "query", dataType = "String", defaultValue =
            "a1106bf4-eeac-4bfa-b010-8fdd5241a5b9")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPoorObjInfoById", method = RequestMethod.GET)
    public CommonResultData<ObjMoveInfoVo> getPoorObjInfoById(@RequestParam String id) {
        CommonResultData<ObjMoveInfoVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcService.getPoorObjInfoById(id);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPoorObjInfoById", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    /**
     * @param areaCode 区域code
     * @param moveType 搬迁类型 （0：所有类型，1：易地扶贫，2：避灾生态）
     * @return
     */
    @ApiOperation(value = "根据区域code和搬迁类型获取各区域搬迁户数和入住户数数据", notes = "根据区域ID和搬迁类型获取各区域搬迁户数和入住户数数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "610000000000"),
            @ApiImplicitParam(name = "moveType", value = "搬迁类型（0：所有类型，1：易地扶贫，2：避灾生态）", required = true, paramType = "query", dataType = "String", defaultValue =
                    "1"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjMoveInStatisticsByAreaCodeAndMoveType", method = RequestMethod.GET)
    public CommonResultData<ObjMoveInStatisticsVo> getObjMoveInStatisticsByAreaCodeAndMoveType(@RequestParam String areaCode, @RequestParam String
            moveType) {
        CommonResultData<ObjMoveInStatisticsVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjMoveInStatisticsByAreaCodeAndMoveType(areaCode, moveType);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjMoveInStatisticsByAreaCodeAndMoveType", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "根据区域code和搬迁类型获取各区域搬迁户数和入住户数数据(上报数据)", notes = "根据区域ID和搬迁类型获取各区域搬迁户数和入住户数数据(上报数据)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "611000000000"),
            @ApiImplicitParam(name = "moveType", value = "搬迁类型（0：所有类型，1：易地扶贫，2：避灾生态）", required = true, paramType = "query", dataType = "String", defaultValue =
                    "1"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjMoveInStatisticsByAreaCodeAndMoveTypeReport", method = RequestMethod.GET)
    public CommonResultData<ObjMoveInStatisticsVo> getObjMoveInStatisticsByAreaCodeAndMoveTypeReport(@RequestParam String areaCode, @RequestParam String
            moveType) {
        CommonResultData<ObjMoveInStatisticsVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjMoveInStatisticsByAreaCodeAndMoveTypeReport(areaCode, moveType);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjMoveInStatisticsByAreaCodeAndMoveTypeReport", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "搬迁户致贫原因统计排行", notes = "搬迁户致贫原因统计排行")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjPoorTypeStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<ObjZPYYVo>> getObjPoorTypeStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<ObjZPYYVo>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjPoorTypeStatisticsByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjPoorTypeStatisticsByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "根据区域code和搬迁类型获取搬迁人口区域类型统计数据", notes = "根据区搬迁类型获取搬迁人口区域类型统计数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "610000000000"),
            @ApiImplicitParam(name = "moveType", value = "搬迁类型（0：所有类型，1：易地扶贫，2：避灾生态）", required = true, paramType = "query", dataType = "String", defaultValue =
                    "1"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getObjPoorAreaTypeStatisticsByMoveType", method = RequestMethod.GET)
    public CommonResultData<List<Map<String,Object>>> getObjPoorAreaTypeStatisticsByMoveType(@RequestParam String areaCode,@RequestParam String
            moveType) {
        CommonResultData<List<Map<String,Object>>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();
            moveTopByAreaCode = fzjcService.getObjPoorAreaTypeStatisticsByMoveType(areaCode,moveType);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getObjPoorAreaTypeStatisticsByMoveType", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

}
